<?php
namespace Admin\Controller;
use Model\ArticleModel;
use Model\TagModel;
use Think\Controller;

/**
 * Created by PhpStorm.
 * User: Yujie
 * Date: 2018/8/31
 * Time: 15:44
 */
class IndexController extends AdminBaseController{

    public function __construct()
    {
        parent::__construct();
    }

    public function index(){
        $this->checkLogin();
        $this->display();
    }


    public function addArticle(){
        $title = $_POST['title'];
        $content = $_POST['content'];
        $tag_id = $_POST['tag'];

        $a_data = ['title' => $title , 'content' => $content , 'tag_id'=>$tag_id , 'c_time'=>time()];
        $db = new ArticleModel();
        $ret = $db->addOne($a_data);
        $this->ajaxReturn($ret,'json');
    }

    /**
     * @function 获取热门标签
     */
    public function getTags(){
        $db = new TagModel();
        $ret = $db->selectAll();

        $this->ajaxReturn($ret,'json');
    }
}